home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: aril@cmt.lpr.mail.carel.fi (Ari Lukumies)
- Newsgroups: comp.lang.c++
- Subject: Re: Using multiple functions in one file
- Date: Thu, 11 Jan 1996 13:51:43 GMT
- Organization: Carelcomp Forest Oy
- Message-ID: <4d3520$kj9@tahko.lpr.carel.fi>
- References: <DL00rI.HFr@cunews.carleton.ca>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- X-Newsreader: Forte Free Agent 1.0.82
-
- abelo@chat.carleton.ca (Andrew Belo) wrote:
-
-
- >I have written an example program out of a book and it keeps giving me an
- >error that says "Call to undefined function 'butler' in function main()"
- >I am using Borland C++ for Dos, Win and Win 32 Version 4.5.
-
- >The book is called C: Step by Step, and the program is as follows.
-
- >/* two_func.c -- a program using two functions in one file */
- >#include <stdio.h>
- >main()
- >{
- > printf("I will summon the butler function. \n");
- > butler();
- > printf("Yes. Bring me some tea and floppy disks.\n");
- >}
- >butler()
- >{
- >printf("You rang, sir? \n");
- >}
-
- >Thanx
-
- The problem here is that your compiler expects that butler be defined
- before it's called. Two solutions: First, you can add a prototype
-
- butler();
-
- before the main() function (ie. between #include and main()). Second,
- you can move the butler() function before the main().
-
- BTW, I'd suggest using ANSI prototyping, if your compiler accepts it:
-
- int main(void); /* Sufficient in your case */
- void butler(void);
-
- Later,
- AriL
-
- All my opinions are mine and mine alone.
-
-